[id].vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- Banner1 -->
  6. <HomeBanner1></HomeBanner1>
  7. <!-- 面包屑导航 -->
  8. <div class="breadcrumb">
  9. <div class="inner">
  10. <span class="location">当前位置:</span>
  11. <el-breadcrumb :separator-icon="ArrowRight">
  12. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item :to="{ path: '/newsList' }">{{ name }}</el-breadcrumb-item>
  14. </el-breadcrumb>
  15. </div>
  16. </div>
  17. <!-- 资讯列表 -->
  18. <div class="newsList">
  19. <div class="inner">
  20. <div class="innerLeft">
  21. <ul class="list">
  22. <li v-for="(item, index) in newsList" :key="index">
  23. <NuxtLink :to="`/newsDetail/${item.id}`" target="_blank">{{ item.title }}</NuxtLink>
  24. </li>
  25. </ul>
  26. <!-- 分页器 -->
  27. <div class="pagination" v-if="total">
  28. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  29. v-model:page-size="pageSize" prev-text="上一页" next-text="下一页" @change="changePage" />
  30. <!-- <HomePagination @sendData="handleData"></HomePagination> -->
  31. </div>
  32. </div>
  33. <div class="innerRight">
  34. <DetailHotNews></DetailHotNews>
  35. <DetailHotNews2></DetailHotNews2>
  36. </div>
  37. </div>
  38. </div>
  39. <!-- 三农资讯logo -->
  40. <HomeSannongzixun></HomeSannongzixun>
  41. <!-- 页面底部 -->
  42. <HomeFoot></HomeFoot>
  43. </div>
  44. </template>
  45. <script setup>
  46. import { onMounted } from 'vue';
  47. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  48. import { ArrowRight } from '@element-plus/icons-vue'
  49. const nuxtApp = useNuxtApp();
  50. const axios = nuxtApp.$axios;
  51. //获得跳转过来的id
  52. const route = useRoute();
  53. const articleId = route.params.id; //获得该页面的id
  54. // const category_id = route.query.category_id; //获得该页面的id
  55. const category_id = route.query.catid; //获得该页面的id
  56. // const name = route.query.name; //获得该页面的id
  57. // console.log(name);
  58. console.log('category_id', category_id);
  59. // 定义响应式数据
  60. const seoData = ref({
  61. title: '三农资讯网',
  62. description: '默认描述',
  63. keywords: '默认关键词',
  64. image: 'https://example.com/default-image.jpg'
  65. });
  66. // 在 onMounted 钩子中获取数据
  67. onMounted(async () => {
  68. try {
  69. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  70. const data = response.data; // 假设接口返回的数据在 data 字段中
  71. console.log(seoData.value.title)
  72. // 更新 seoData
  73. seoData.value = {
  74. title: data.seo_title,
  75. description: data.seo_description,
  76. keywords: data.seo_keywords,
  77. image: data.seo_image
  78. };
  79. console.log(seoData.value.title)
  80. } catch (error) {
  81. console.error('获取 SEO 数据失败:', error);
  82. // 设置默认值
  83. seoData.value = {
  84. title: '三农资讯网',
  85. description: '默认描述',
  86. keywords: '默认关键词',
  87. image: 'https://example.com/default-image.jpg'
  88. };
  89. }
  90. });
  91. // 监听 seoData 的变化,动态设置 SEO 字段
  92. watch(seoData, (newVal) => {
  93. if (newVal.title) { // 确保 title 有值
  94. useSeoMeta({
  95. title: newVal.title, // 使用动态值
  96. description: newVal.description,
  97. ogTitle: newVal.title,
  98. ogDescription: newVal.description,
  99. ogImage: newVal.image,
  100. twitterTitle: newVal.title,
  101. twitterDescription: newVal.description,
  102. twitterImage: newVal.image,
  103. keywords: newVal.keywords
  104. });
  105. }
  106. }, { immediate: true });
  107. //关键词
  108. let keyWord = useState("keyWord", () => "")
  109. let id = useState("id", () => "")
  110. let total = useState("total", () => 0)
  111. let page = useState("page", () => 1)
  112. let pageSize = useState("pageSize", () => 20)
  113. onMounted(() => {
  114. id.value = route.query.id;
  115. console.log('id', id.value);
  116. })
  117. // 页码
  118. // //页面组件传递数据的时间驱动函数
  119. // const handleData = (data) => {
  120. // console.log(data.value)
  121. // page.value = data.value
  122. // //在页码发生变化时去请求响应页面的新闻数据
  123. // axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${10}&catid=${14}&keyword=${keyWord.value}`).then(response => {
  124. // // console.log(response.data.rows);
  125. // newsList.value = response.data.rows;
  126. // }).catch(error => {
  127. // console.error(error);
  128. // })
  129. // }
  130. let changePage = (value) => {
  131. console.log("当前页码", value);
  132. page.value = value
  133. console.log(page.value);
  134. newslists()
  135. }
  136. // 一级导航
  137. const navigation1 = ref("");
  138. const navigateList = async () => {
  139. try {
  140. const response = await axios.get(`/web/getWebsiteModelCategory?placeid=${1}&pid=${0}&num=${24}`);
  141. console.log('一级导航', response.data);
  142. navigation1.value = response.data;
  143. console.log('111111111111111111111111111', navigation1[0]?.value.category_id);
  144. } catch (error) {
  145. console.error(error);
  146. }
  147. }
  148. // 新闻列表
  149. const newsList = useState("newsList", () => '');
  150. const newslists = async () => {
  151. try {
  152. const response = await axios.get(`/web/getWebsiteArticleList?page=${page.value}&pageSize=${pageSize.value}&catid=${articleId}`);
  153. // console.log(response.data.rows);
  154. newsList.value = response.data.rows;
  155. total.value = response.data.count;
  156. } catch (error) {
  157. console.error(error);
  158. }
  159. }
  160. //热点资讯
  161. const hotlistall = useState("hotlistall", () => "");
  162. const hotlist = async () => {
  163. try {
  164. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${2}&level=${4}&placeid=${1}`);
  165. console.log('热点资讯', response.data);
  166. for (let item of response.data) {
  167. console.log(item);
  168. item.count = 1;
  169. }
  170. hotlistall.value = response.data;
  171. } catch (error) {
  172. console.error(error);
  173. }
  174. }
  175. //资讯推荐1
  176. const news1 = useState("news1", () => "");
  177. const newslist1 = async () => {
  178. try {
  179. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  180. console.log('热点资讯', response.data);
  181. news1.value = response.data;
  182. } catch (error) {
  183. console.error(error);
  184. }
  185. }
  186. const news11 = useState("news11", () => "");
  187. const newslist11 = async () => {
  188. try {
  189. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  190. console.log('热点资讯', response.data);
  191. news11.value = response.data;
  192. } catch (error) {
  193. console.error(error);
  194. }
  195. }
  196. //资讯推荐2
  197. const news2 = useState("news2", () => "");
  198. const newslist2 = async () => {
  199. try {
  200. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${1}&level=${5}&placeid=${1}`);
  201. console.log('热点资讯', response.data);
  202. news2.value = response.data;
  203. } catch (error) {
  204. console.error(error);
  205. }
  206. }
  207. const news22 = useState("news22", () => "");
  208. const newslist22 = async () => {
  209. try {
  210. const response = await axios.get(`/web/getWebsiteArticlett?pageSize=${3}&level=${5}&placeid=${1}`);
  211. console.log('热点资讯', response.data);
  212. news22.value = response.data;
  213. } catch (error) {
  214. console.error(error);
  215. }
  216. }
  217. const name = useState("name", () => "");
  218. const name1 = async () => {
  219. try {
  220. const response = await axios.get(`/web/getOneWebsiteCategory?catid=${articleId}`);
  221. console.log('name11111111', response.data);
  222. name.value = response.data.name;
  223. navigateList()
  224. } catch (error) {
  225. console.error(error);
  226. }
  227. }
  228. //挂载成功钩子函数
  229. onMounted(() => {
  230. name1()
  231. // 资讯推荐
  232. newslists()
  233. // 热点资讯
  234. hotlist()
  235. // 资讯推荐
  236. newslist1()
  237. newslist2()
  238. // 热点资讯
  239. newslist11()
  240. newslist22()
  241. // navigateList()
  242. })
  243. //路由中间件
  244. definePageMeta({
  245. middleware: 'auth'
  246. })
  247. </script>
  248. <style lang="less" scoped>
  249. #newsList {
  250. width: 100%;
  251. overflow: hidden;
  252. }
  253. //导航条
  254. .breadcrumb {
  255. width: 100%;
  256. height: 22px;
  257. margin-bottom: 30px;
  258. font-family: Microsoft YaHei, Microsoft YaHei;
  259. font-weight: 400;
  260. font-size: 20px;
  261. color: #666666;
  262. line-height: 23px;
  263. text-align: left;
  264. font-style: normal;
  265. text-transform: none;
  266. :deep(.el-breadcrumb) {
  267. display: inline-block;
  268. vertical-align: -4px;
  269. }
  270. :deep(.el-breadcrumb__inner a),
  271. :deep(.el-breadcrumb__inner.is-link) {
  272. color: #666666;
  273. font-weight: 400;
  274. text-decoration: none;
  275. transition: var(--el-transition-color);
  276. }
  277. span {
  278. font-family: Microsoft YaHei, Microsoft YaHei;
  279. font-weight: 400;
  280. font-size: 20px;
  281. color: #666666;
  282. line-height: 23px;
  283. text-align: left;
  284. font-style: normal;
  285. text-transform: none;
  286. }
  287. span:hover {
  288. color: #666666;
  289. }
  290. .location {
  291. margin-right: 20px;
  292. width: 100px;
  293. height: 22px;
  294. font-family: Microsoft YaHei, Microsoft YaHei;
  295. font-weight: 400;
  296. font-size: 20px;
  297. color: #666666;
  298. line-height: 23px;
  299. text-align: left;
  300. font-style: normal;
  301. text-transform: none;
  302. }
  303. }
  304. // 资讯列表
  305. .newsList {
  306. width: 100%;
  307. // height: 675px;
  308. overflow: hidden;
  309. margin-bottom: 70px;
  310. .inner {
  311. width: 1200px;
  312. .innerLeft,
  313. .innerRight {
  314. border-top: 1px solid #139602;
  315. }
  316. .innerLeft {
  317. // height: 675px;
  318. >.list {
  319. // height: 570px;
  320. margin-bottom: 70px;
  321. >li {
  322. width: 790px;
  323. height: 56px;
  324. white-space: nowrap;
  325. overflow: hidden;
  326. text-overflow: ellipsis;
  327. line-height: 56px;
  328. >a {
  329. width: 360px;
  330. height: 26px;
  331. font-family: Microsoft YaHei, Microsoft YaHei;
  332. font-weight: 400;
  333. font-size: 20px;
  334. color: #333333;
  335. line-height: 26px;
  336. text-align: left;
  337. font-style: normal;
  338. text-transform: none;
  339. }
  340. }
  341. >li:hover>a {
  342. color: #139602;
  343. }
  344. >li:nth-child(1)::after,
  345. >li:nth-child(2)::after {
  346. content: "热";
  347. margin-left: 13px;
  348. background: #FF8A37;
  349. color: #fff;
  350. font-size: 14px;
  351. padding: 0px 2px;
  352. }
  353. >li:nth-child(5n) {
  354. // padding-top: 10px;
  355. // padding-bottom: 10px;
  356. border-bottom: 1px solid #D9D9D9;
  357. }
  358. }
  359. >.pagination {
  360. width: 800px;
  361. height: 34px;
  362. margin-left: 141px;
  363. display: flex;
  364. justify-content: center;
  365. margin: 0;
  366. // 鼠标移入后字体颜色
  367. .el-pagination::v-deep :hover {
  368. color: #139609;
  369. }
  370. .el-pagination.is-background::v-deep .btn-next,
  371. .el-pagination.is-background::v-deep .btn-prev {
  372. width: 70px;
  373. height: 34px;
  374. margin: 0px 10px;
  375. border-radius: 4px;
  376. }
  377. .el-pagination.is-background::v-deep .el-pager li {
  378. margin: 0px 10px;
  379. width: 38px;
  380. height: 34px;
  381. border-radius: 4px;
  382. }
  383. .el-pagination.is-background::v-deep .btn-next.is-active,
  384. .el-pagination.is-background::v-deep .btn-prev.is-active,
  385. .el-pagination.is-background::v-deep .el-pager li.is-active {
  386. background-color: #028e21;
  387. color: #fff;
  388. }
  389. }
  390. }
  391. .innerRight {
  392. width: 381px;
  393. // height: 605px;
  394. }
  395. }
  396. }
  397. //资讯推荐
  398. .zixuntuijian {
  399. width: 100%;
  400. height: 290px;
  401. margin-bottom: 70px;
  402. .innerLeft {
  403. // 左侧
  404. .zixunLeft {
  405. margin-right: 30px;
  406. }
  407. .zixunRight,
  408. .zixunLeft {
  409. float: left;
  410. width: 380px;
  411. height: 290px;
  412. // 标题部分
  413. >.title {
  414. width: 380px;
  415. }
  416. >.title>h3 {
  417. height: 36px;
  418. font-family: Source Han Sans, Source Han Sans;
  419. font-weight: bold;
  420. font-size: 24px;
  421. color: #000000;
  422. line-height: 28px;
  423. text-align: left;
  424. font-style: normal;
  425. text-transform: none;
  426. border-bottom: 1px solid #139602;
  427. }
  428. >.title>h3>span {
  429. float: right;
  430. width: 56px;
  431. height: 20px;
  432. line-height: 24px;
  433. font-weight: 400;
  434. font-size: 14px;
  435. color: #999999;
  436. font-style: normal;
  437. text-transform: none;
  438. }
  439. .photo_text {
  440. >li:first-child {
  441. width: 380px;
  442. height: 120px;
  443. margin-top: 20px;
  444. margin-bottom: 15px;
  445. position: relative;
  446. >img {
  447. float: left;
  448. width: 160px;
  449. height: 120px;
  450. }
  451. >div {
  452. float: left;
  453. width: 220px;
  454. height: 120px;
  455. padding-left: 15px;
  456. padding-top: 6px;
  457. box-sizing: border-box;
  458. background-color: #f6f6f6;
  459. >h5 {
  460. width: 200px;
  461. height: 54px;
  462. display: -webkit-box;
  463. -webkit-box-orient: vertical;
  464. -webkit-line-clamp: 2;
  465. overflow: hidden;
  466. text-overflow: ellipsis;
  467. word-break: break-all;
  468. font-family: Source Han Sans, Source Han Sans;
  469. font-weight: 500;
  470. font-size: 18px;
  471. color: #333333;
  472. line-height: 26px;
  473. text-align: left;
  474. font-style: normal;
  475. text-transform: none;
  476. }
  477. >p {
  478. width: 200px;
  479. height: 22px;
  480. line-height: 20px;
  481. position: absolute;
  482. bottom: 5px;
  483. right: 0;
  484. >span {
  485. display: inline-block;
  486. // width: 100px;
  487. height: 18px;
  488. font-family: Source Han Sans, Source Han Sans;
  489. font-weight: 400;
  490. font-size: 12px;
  491. color: #999999;
  492. text-align: left;
  493. line-height: 14px;
  494. font-style: normal;
  495. text-transform: none;
  496. }
  497. >span:last-child {
  498. // width: 90px;
  499. text-align: right;
  500. margin-left: 20px;
  501. }
  502. }
  503. }
  504. }
  505. >li {
  506. width: 380px;
  507. height: 25px;
  508. white-space: nowrap;
  509. overflow: hidden;
  510. text-overflow: ellipsis;
  511. font-family: PingFang SC, PingFang SC;
  512. font-weight: 500;
  513. font-size: 18px;
  514. color: #333333;
  515. line-height: 21px;
  516. text-align: left;
  517. font-style: normal;
  518. text-transform: none;
  519. margin-bottom: 10px;
  520. em {
  521. display: inline-block;
  522. width: 8px;
  523. height: 8px;
  524. border-radius: 8px;
  525. margin-right: 10px;
  526. background-color: #d9d9d9;
  527. }
  528. }
  529. >li:hover {
  530. color: #139602;
  531. }
  532. >li:hover em {
  533. background-color: #139602;
  534. }
  535. }
  536. }
  537. }
  538. .innerRight {
  539. width: 381px;
  540. height: 290px;
  541. background-color: #fbfbfb;
  542. >.title {
  543. width: 380px;
  544. height: 40px;
  545. line-height: 40px;
  546. border-top: 1px solid #139602;
  547. border-bottom: 1px solid #e7e7e7;
  548. >h4 {
  549. font-family: Microsoft YaHei, Microsoft YaHei;
  550. font-weight: 400;
  551. margin-left: 20px;
  552. font-size: 20px;
  553. color: #000000;
  554. text-align: left;
  555. font-style: normal;
  556. text-transform: none;
  557. >span {
  558. float: right;
  559. font-family: Microsoft YaHei, Microsoft YaHei;
  560. font-weight: 400;
  561. font-size: 14px;
  562. margin-right: 10px;
  563. color: #999999;
  564. text-align: left;
  565. font-style: normal;
  566. text-transform: none;
  567. }
  568. }
  569. }
  570. .rightList {
  571. height: 540px;
  572. margin-top: 20px;
  573. >li {
  574. height: 100px;
  575. margin-bottom: 10px;
  576. >img {
  577. width: 150px;
  578. height: 100px;
  579. }
  580. >p {
  581. width: 219px;
  582. height: 100px;
  583. padding-left: 12px;
  584. font-family: PingFang SC, PingFang SC;
  585. font-weight: 400;
  586. font-size: 16px;
  587. color: #333333;
  588. line-height: 22px;
  589. text-align: left;
  590. font-style: normal;
  591. text-transform: none;
  592. }
  593. >p:hover {
  594. box-shadow: 0 0 16px 1px rgba(0, 0, 0, 0.1);
  595. }
  596. }
  597. }
  598. }
  599. }
  600. </style>